/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.execute.service.impl;

import cn.hutool.core.io.FileTypeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.dto.FileInfoSaveDto;
import com.icinfo.cloud.provider.common.enums.FileTransferFormEnum;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.oss.service.IOssOperateService;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.common.utils.HttpUtils;
import com.icinfo.cloud.provider.punish.approval.constant.AuditStatusConstant;
import com.icinfo.cloud.provider.punish.approval.vo.WaitPageEachColorNumVo;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.DocumentRelateAttachmentVo;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentRecordStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentStatusEnum;
import com.icinfo.cloud.provider.punish.common.nonlitigation.service.impl.CaseNonLitigationExecuteRecordServiceImpl;
import com.icinfo.cloud.provider.punish.config.dto.ConfigDictionaryInfoQueryDto;
import com.icinfo.cloud.provider.punish.config.mapper.ConfigBusiParamDocumentInfoMapper;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.model.SysDepartParam;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.service.IConfigDictionaryInfoService;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigDictionaryInfoVo;
import com.icinfo.cloud.provider.punish.execute.dto.*;
import com.icinfo.cloud.provider.punish.execute.enums.CourtCertTypeEnum;
import com.icinfo.cloud.provider.punish.execute.enums.ExecuteStateEnum;
import com.icinfo.cloud.provider.punish.execute.enums.ExecuteStatusEnum;
import com.icinfo.cloud.provider.punish.execute.mapper.*;
import com.icinfo.cloud.provider.punish.execute.model.*;
import com.icinfo.cloud.provider.punish.execute.service.*;
import com.icinfo.cloud.provider.punish.execute.vo.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.AppendixDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseAttachmentInfoSaveDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.AttachmentTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.HandlePersonTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseDocumentRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartyRelateDocInfoVo;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import com.icinfo.framework.tools.utils.MapUtils;
import com.icinfo.framework.tools.utils.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 描述: 裁执分离主表 execute_main_info 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年08月24日
 */
@Service
public class ExecuteMainInfoServiceImpl extends MyBatisServiceSupport implements IExecuteMainInfoService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ExecuteMainInfoServiceImpl.class);

    @Value("${nonLitigation.url}")
    private String url;

    @Value("${nonLitigation.api.czflJahd}")
    private String czflJahd;

    @Resource
    private ExecuteMainInfoMapper executeMainInfoMapper;
    @Resource
    private ExecutePartyInfoMapper executePartyInfoMapper;
    @Resource
    private ExecuteFilesRecordMapper executeFilesRecordMapper;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Autowired
    private IExecuteFlowRecordService executeFlowRecordService;
    @Resource
    private ExecuteFlowRecordMapper executeFlowRecordMapper;
    @Resource
    private ConfigBusiParamDocumentInfoMapper configBusiParamDocumentInfoMapper;
    @Resource
    private ExecuteDocumentRecordMapper executeDocumentRecordMapper;
    @Resource
    private IExecuteDocumentRecordService executeDocumentRecordService;
    @Resource
    private IExecuteFilesRecordService executeFilesRecordService;
    @Resource
    private IConfigDictionaryInfoService configDictionaryInfoService;
    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;
    @Resource
    private IExecuteHandlePersonRecordService executeHandlePersonRecordService;
    @Resource
    private IExecutePartyInfoService executePartyInfoService;
    @Resource
    private IExecuteCluHandoutRecordService executeCluHandoutRecordService;
    @Resource
    private ExecuteAppendixRecordMapper executeAppendixRecordMapper;
    @Resource
    private CaseNonLitigationExecuteRecordServiceImpl caseNonLitigationExecuteRecordService;
    @Resource
    private ExecuteCompleteRecordMapper executeCompleteRecordMapper;

    @Resource
    private IExecuteCompleteRecordService executeCompleteRecordService;
    @Resource
    private ExecuteCallbackRecordMapper executeCallbackRecordMapper;

    @Resource
    private ISysDepartParamService sysDepartParamService;

    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private IExecuteDocCommonOperateService executeDocCommonOperateService;
    public static final List<String> PREVENT_DEAL_CASE_STATUS_LIST;
    static {

        PREVENT_DEAL_CASE_STATUS_LIST = new ArrayList<>();
        PREVENT_DEAL_CASE_STATUS_LIST.add(ExecuteStateEnum.ACCEPT_CASE.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(ExecuteStateEnum.CASE_CLOSED.getCode());

    }

    @Resource
    private IOssOperateService iOssOperateService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<String> saveExecuteMainInfo(ExecuteMainInfoInsertDto saveDto) {
        // 案件唯一id
        String executeId = saveDto.getExecuteId();
        ExecuteMainInfo executeMainInfo = new ExecuteMainInfo();
        executeMainInfo.setExecuteId(executeId);
        ExecuteMainInfo executeMainInfo1 = executeMainInfoMapper.selectOne(executeMainInfo);
        if (!ObjectUtils.isEmpty(executeMainInfo1)) {
            return Result.error("无需重复推送案件");
        }
        // 获取裁执分离案件信息
        BeanUtils.copyProperties(saveDto, executeMainInfo);
        executeMainInfo.setId(StringUtils.uuid());
        LocalDateTime nowDate = LocalDateTime.now();
        executeMainInfo.setAcceptanceTime(nowDate);
        // 执行截止日期默认推后90天
        executeMainInfo.setExecutionDeadlineTime(nowDate.plusDays(90));
        executeMainInfo.setExecuteState(ExecuteStateEnum.ACCEPT_CASE.getCode());
        //待指派
        executeMainInfo.setCaseStatus(ExecuteStatusEnum.TO_DISPATCH.getIndex());
        executeMainInfoMapper.insertSelective(executeMainInfo);
        // 获取当事人信息/被申请人
        List<ExecutePartyInfo> partyInfos = saveDto.getPartyInfos();
        for (ExecutePartyInfo partyInfo : partyInfos) {
            partyInfo.setId(StringUtils.uuid());
            partyInfo.setExecuteId(executeId);
            executePartyInfoMapper.insertSelective(partyInfo);
        }
        List<ExecuteFilesRecord> executeFilesRecords = saveDto.getExecuteFilesRecords();
        // 将法院文件上传到我们的sso先注释，
        /*FilePreviewAddressDto filePreviewAddressDto = new FilePreviewAddressDto();
        filePreviewAddressDto.setCourtCode(saveDto.getCourtCode());*/
        for (ExecuteFilesRecord executeFilesRecord : executeFilesRecords) {
            executeFilesRecord.setId(StringUtils.uuid());
            executeFilesRecord.setExecuteId(executeId);
            /*filePreviewAddressDto.setFileUrl(executeFilesRecord.getFileUrl());
            String filePreviewAddress = executeFilesRecordService.getFilePreviewAddress(filePreviewAddressDto);
            String realUrl = "";
            if (StringUtils.isBlank(filePreviewAddress)) {
                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(filePreviewAddressDto);
                throw new BusinessException("获取法院文件服务地址失败，参数：" + jsonObject);
            }
            try {
                realUrl = ossLocalFileSaving(filePreviewAddress);
            } catch (IOException e) {
                throw new BusinessException("系统Oss文件上传失败，参数：" + filePreviewAddress);
            }
            if (StringUtils.isBlank(realUrl)) {
                throw new BusinessException("系统Oss文件上传失败，参数：" + filePreviewAddress);
            } else {
                executeFilesRecord.setFileUrl(filePreviewAddress);
            }*/
            executeFilesRecordMapper.insertSelective(executeFilesRecord);
        }
        ExecuteFlowRecord executeFlowRecord = new ExecuteFlowRecord();
        executeFlowRecord.setId(StringUtils.uuid());
        executeFlowRecord.setExecuteId(executeId);
        executeFlowRecord.setFlowStartTime(new Date());
        executeFlowRecord.setFlowStageType(ExecuteStatusEnum.TO_DISPATCH.getIndex());
        executeFlowRecord.setFlowStageName(ExecuteStateEnum.ACCEPT_CASE.getDes());
        executeFlowRecord.setFlowStageCode(ExecuteStateEnum.ACCEPT_CASE.getCode());
        executeFlowRecordMapper.insertSelective(executeFlowRecord);
        return Result.success("数据接收成功");
    }

    public String ossLocalFileSaving(String url) throws IOException {
        byte[] read = read(url);
        //上传oss
        FileInfoSaveDto fileInfo = new FileInfoSaveDto();
        fileInfo.setFileBytes(read);
        fileInfo.setFileTransferForm(FileTransferFormEnum.FILE_TRANSFER_FORM_3.getCode());
        fileInfo.setFileType(FileTypeUtil.getType(new URL(url).openStream()));
        Result result = iOssOperateService.uploadFile(fileInfo);
        if (!ObjectUtils.isEmpty(result)) {
            Object data = result.getData();
            if (ObjectUtils.isEmpty(data)) {
                throw new BusinessException("获取本地oss文件地址失败");
            } else {
                return data.toString();
            }
        } else {
            throw new BusinessException("generateQrCode upload file to oss fail-response is null");
        }
    }

    public byte[] read(String fileUrl) throws IOException {
        URL url = new URL(fileUrl);
        byte[] buffer = new byte[1024];
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        con.setConnectTimeout(4 * 1000);
        // 获取文件流
        InputStream inputStream = con.getInputStream();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int num = inputStream.read(buffer);
            while (num != -1) {
                baos.write(buffer, 0, num);
                num = inputStream.read(buffer);
            }
            baos.flush();
            return baos.toByteArray();
        } catch (IOException e) {
            logger.error("获取文件失败,文件路径:" + fileUrl);
            logger.error(e.getMessage());
            throw new BusinessException("获取文件失败,文件路径:" + fileUrl);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }

    @Override
    public List<ExecuteMainInfoVo> getExecuteMainList(ExecuteMainInfoRequest request) {
        // 人员权限暂且放开
        UserDTO userInfo = UserUtil.getUserInfo();
        request.setLoginUserOrgCode(userInfo.getOrgCode());
        // 我的裁执分离
        if (request.getMenuStatus().equals(Constant.INTEGER_2)) {
            request.setLoginPersonId(userInfo.getUserId().toString());
        } else {
            request.setLoginPersonId(null);
        }
        PageHelper.startPage(request.getPageNum(), request.getLength(), request.getOrderBy());
        List<ExecuteMainInfoVo> executeMainInfoVos = executeMainInfoMapper.selectExecuteMainList(request);
        executeMainInfoVos.forEach(executeMainInfoVo -> {
            String executeId = executeMainInfoVo.getExecuteId();
            List<ExecutePartyNameVo> executePartyNameVos = executePartyInfoMapper.selectPartyName(executeId);
            if (ObjectUtil.isNotEmpty(executePartyNameVos)) {
                for (ExecutePartyNameVo executePartyNameVo : executePartyNameVos) {
                    executePartyNameVo.setPartyIdentityType(CourtCertTypeEnum.getValueByCode(executePartyNameVo.getPartyIdentityType()));
                    executePartyNameVo.setLegalCertType(CourtCertTypeEnum.getValueByCode(executePartyNameVo.getLegalCertType()));
                }
                // 多当事人
                if (executePartyNameVos.size() > 1) {
                    executeMainInfoVo.setPartyName(executePartyNameVos.get(0).getPartyName() + "等" + executePartyNameVos.size() + "个");
                    executeMainInfoVo.setPartyType("multitude");
                } else {
                    executeMainInfoVo.setPartyName(executePartyNameVos.get(0).getPartyName());
                    executeMainInfoVo.setPartyIdentityCode(executePartyNameVos.get(0).getPartyIdentityCode());
                    executeMainInfoVo.setPartyType(executePartyNameVos.get(0).getPartyType());
                }
            }
            // 当事人信息
            executeMainInfoVo.setExecutePartyNameVos(executePartyNameVos);
            executeMainInfoVo.setExecuteState(ExecuteStateEnum.getValueByCode(executeMainInfoVo.getExecuteState()));
            //case_document_record判断是否在我们系统中存在
            //行政处罚决定书编号
            String decisionNumber = executeMainInfoVo.getDecisionNumber();
            CaseDocumentRecord caseDocumentRecord = new CaseDocumentRecord();
            caseDocumentRecord.setDocumentNumber(decisionNumber);
            CaseDocumentRecord caseDocumentRecord1 = caseDocumentRecordMapper.selectOne(caseDocumentRecord);
            if (!ObjectUtils.isEmpty(caseDocumentRecord1)) {
                // 行政处罚决定书编号存在本系统
                executeMainInfoVo.setIsDecision(Constant.STRING_1);
                executeMainInfoVo.setCaseType(caseMainInfoMapper.selectByPrimaryKey(caseDocumentRecord1.getCaseId()).getCaseType());
                executeMainInfoVo.setCaseId(caseDocumentRecord1.getCaseId());
            }
            Integer daysRemaining = executeMainInfoVo.getDaysRemaining();
            if (daysRemaining < 0) {
                executeMainInfoVo.setTimeColor("red");
            }
            if (daysRemaining < 30 && daysRemaining >= 0) {
                executeMainInfoVo.setTimeColor("yellow");
            }
            if (daysRemaining >= 30) {
                executeMainInfoVo.setTimeColor("blue");
            }
        });
        return executeMainInfoVos;
    }

    @Override
    public ExecuteDetailVo getExecuteDetail(ExecuteDetailDto executeDetailDto) {
        ExecuteDetailVo vo = new ExecuteDetailVo();
        ExecuteMainInfo executeQuery = new ExecuteMainInfo();
        executeQuery.setExecuteId(executeDetailDto.getExecuteId());
        List<ExecuteMainInfo> executeList = executeMainInfoMapper.select(executeQuery);
        if (executeList != null && executeList.size() > 0) {
            BeanUtils.copyProperties(executeList.get(0), vo);
        }
        //查询最新的流转状态
        ExecuteFlowRecord executeFlowRecord = executeFlowRecordService.getLastExecuteFlowRecord(executeDetailDto.getExecuteId());
        String isShowButton = "";
        UserDTO userDTO = UserUtil.getUserInfo();
        String userId = userDTO.getUserId().toString();
        String orgCode = userDTO.getOrgCode();
        if (Constant.CASE_SOURCE_STAGE_AYZP.equals(executeFlowRecord.getFlowStageType()) && (userId.equals(vo.getHandlePersonMainId()) || userId.equals(vo.getHandlePersonAssistId())) && orgCode.equals(vo.getExecuteOrgCode())) {
            isShowButton = Constant.STRING_1;
        } else {
            isShowButton = Constant.STRING_0;
        }
        vo.setIsShowButton(isShowButton);
        //设置是否多当事人
        Example partyExample = new Example(ExecutePartyInfo.class);
        partyExample.createCriteria().andEqualTo("executeId", executeDetailDto.getExecuteId()).andEqualTo("status", Constant.STRING_1);
        List<ExecutePartyInfo> executePartyInfos = executePartyInfoMapper.selectByExample(partyExample);
        vo.setCaseSourcePartiesType(Constant.STRING_0);
        if (null != executePartyInfos && executePartyInfos.size() > 1) {
            vo.setCaseSourcePartiesType(Constant.STRING_1);
        }
        //附件信息表 - 待确认是否有该信息
        //当前阶段可选审批表列表
        List<ExecuteDetailOperateDocInfoVo> executeDetailOperateApprovalTableInfoVoList = new ArrayList<>();
        //当前阶段可选文书列表
        List<ExecuteDetailOperateDocInfoVo> executeDetailOperateDocInfoVoList = new ArrayList<>();
        //查询所有文书
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andLike("applyGroup", "CZFL%");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        configBusiParamDocumentInfos.forEach(configBusiParamDocumentInfo -> {
            ExecuteDetailOperateDocInfoVo executeDetailOperateDocInfoVo = new ExecuteDetailOperateDocInfoVo();
            executeDetailOperateDocInfoVo.setDocumentKindCode(configBusiParamDocumentInfo.getDocumentKindCode());
            executeDetailOperateDocInfoVo.setDocumentKindName(configBusiParamDocumentInfo.getDocumentKindName());
            executeDetailOperateDocInfoVo.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
            executeDetailOperateDocInfoVo.setIsNeedApproval(configBusiParamDocumentInfo.getIsApprove());
            executeDetailOperateDocInfoVo.setAllRelationDocCatalogCodeList(null);
            executeDetailOperateDocInfoVo.setCaseDocumentTypeFlag(null);
            if("QZZXGG".equals(configBusiParamDocumentInfo.getDocumentKindCode())){
                executeDetailOperateDocInfoVo.setCaseDocumentTypeFlag(Constant.STRING_1);
            }
            executeDetailOperateDocInfoVo.setExecuteId(executeDetailDto.getExecuteId());
            List<CasePartyRelateDocInfoVo> casePartiesKeyInfoVos = new ArrayList<>();
            CasePartyRelateDocInfoVo casePartyRelateDocInfo;
            for (ExecutePartyInfo party : executePartyInfos) {
                casePartyRelateDocInfo = new CasePartyRelateDocInfoVo();
                BeanUtils.copyProperties(party, casePartyRelateDocInfo);
                casePartyRelateDocInfo.setPartyId(party.getId());
                casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.NO.getCode());
                //查看该当事人是否已经添加该文书
                Example queryCountExample = new Example(ExecuteDocumentRecord.class);
                queryCountExample.createCriteria().andEqualTo("executeId", executeDetailDto.getExecuteId())
                        .andEqualTo("documentCatalogCode", configBusiParamDocumentInfo.getDocumentCatalogCode())
                        .andEqualTo("partyId", casePartyRelateDocInfo.getPartyId())
                        //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                        .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
                int count = executeDocumentRecordMapper.selectCountByExample(queryCountExample);
                if (count > 0) {
                    casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.YES.getCode());
                }
                casePartyRelateDocInfo.setIsAddedThisDocName(YesOrNoEnum
                        .getValueByCode(casePartyRelateDocInfo.getIsAddedThisDoc()));
                casePartiesKeyInfoVos.add(casePartyRelateDocInfo);
            }
            executeDetailOperateDocInfoVo.setDocRelatePartiesList(casePartiesKeyInfoVos);
            executeDetailOperateDocInfoVo.setDocumentLinkObjectType(configBusiParamDocumentInfo.getDocumentLinkObjectType());
            //审批表
            if (Constant.STRING_1.equals(configBusiParamDocumentInfo.getDocumentType())) {
                executeDetailOperateApprovalTableInfoVoList.add(executeDetailOperateDocInfoVo);
                //caseDetailOperateDocInfoVo.setDocIsExistsAndWaitToSignRelatedPartyIdList();
            }
            //法律文书
            if (Constant.STRING_2.equals(configBusiParamDocumentInfo.getDocumentType())) {
                executeDetailOperateDocInfoVoList.add(executeDetailOperateDocInfoVo);
            }
        });
        return vo;
    }

    @Override
    public ExecuteMainInfo getByExecuteId(String executeId) {
        ExecuteMainInfo executeQuery = new ExecuteMainInfo();
        executeQuery.setExecuteId(executeId);
        List<ExecuteMainInfo> executeList = executeMainInfoMapper.select(executeQuery);
        if (executeList != null && executeList.size() > 0) {
            return executeList.get(0);
        }
        return null;
    }


    @Override
    public WaitPageEachColorNumVo getExecutePrescription(ExecuteMainInfoRequest request) {
        //获取当前用户
        UserDTO userInfo = UserUtil.getUserInfo();
        request.setLoginUserOrgCode(userInfo.getOrgCode());
        // 我的裁执分离
        if (request.getMenuStatus().equals(Constant.INTEGER_2)) {
            request.setLoginPersonId(userInfo.getUserId().toString());
        } else {
            request.setLoginPersonId(null);
        }
        request.setPrescription(null);
        WaitPageEachColorNumVo waitPageEachColorNumVo = executeMainInfoMapper.selectExecutePrescription(request);
        waitPageEachColorNumVo.setTotal(waitPageEachColorNumVo.getBlueNum() + waitPageEachColorNumVo.getYellowNum() + waitPageEachColorNumVo.getRedNum());
        return waitPageEachColorNumVo;
    }

    @Override
    public ExecuteStatesNumVo getExecuteStatesNum(ExecuteMainInfoRequest request) {
        //获取当前用户
        UserDTO userInfo = UserUtil.getUserInfo();
        request.setLoginUserOrgCode(userInfo.getOrgCode());
        // 我的裁执分离
        if (request.getMenuStatus().equals(Constant.INTEGER_2)) {
            request.setLoginPersonId(userInfo.getUserId().toString());
        } else {
            request.setLoginPersonId(null);
        }
        ExecuteStatesNumVo executeStatesNumVo = new ExecuteStatesNumVo();
        request.setExecutionStatus(Constant.STRING_1);
        executeStatesNumVo.setStayNum(executeMainInfoMapper.selectExecuteMainCount(request));
        request.setExecutionStatus(Constant.STRING_2);
        executeStatesNumVo.setHoldNum(executeMainInfoMapper.selectExecuteMainCount(request));
        request.setExecutionStatus(Constant.STRING_3);
        executeStatesNumVo.setEndNum(executeMainInfoMapper.selectExecuteMainCount(request));
        //executeStatesNumVo.setTotal(executeStatesNumVo.getStayNum() + executeStatesNumVo.getHoldNum() + executeStatesNumVo.getEndNum());
        return executeStatesNumVo;
    }

    @Override
    public ExecuteDetailVo getExecuteMainInfo(ExecuteDetailDto executeDetailDto) {
        ExecuteDetailVo vo = new ExecuteDetailVo();
        ExecuteMainInfo executeMainInfo = getByExecuteId(executeDetailDto.getExecuteId());
        BeanUtils.copyProperties(executeMainInfo, vo);

        //设置当前状态信息
        vo.setExecuteCurrentStageCode(executeMainInfo.getExecuteState());
        vo.setExecuteCurrentStageName(ExecuteStateEnum.getValueByCode(executeMainInfo.getExecuteState()));
        UserDTO userInfo = UserUtil.getUserInfo();
        String userId = String.valueOf(userInfo.getUserId());
        //执行人信息
        AtomicBoolean isCaseHandlerTemp = new AtomicBoolean(false);
        List<ExecuteHandlePersonRecordVo> handlePersonRecordList = executeHandlePersonRecordService.getCaseHandlePersonRecordListByExecuteId(executeDetailDto.getExecuteId());
        vo.setExecuteHandlePersonList(handlePersonRecordList);
        if (!ObjectUtils.isEmpty(handlePersonRecordList) && handlePersonRecordList.size() > 0) {

            handlePersonRecordList.forEach(e -> {
                if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())
                        && ObjectUtils.isEmpty(vo.getExecuteHandlingDeptInfo())) {
                    String caseHandlingDeptInfo = e.getHandleOrgName() + "/" + e.getHandleDeptName();
                    //办案部门
                    vo.setExecuteHandlingDeptInfo(caseHandlingDeptInfo);
                }
                if (userId.equals(Long.valueOf(e.getHandlePersonId())) && !isCaseHandlerTemp.get()) {
                    isCaseHandlerTemp.set(true);
                    vo.setIsExecuteHandler(YesOrNoEnum.YES.getCode());
                    vo.setIsExecuteHandlerName(YesOrNoEnum.YES.getDes());
                }
            });

        }
        //非结案状态和非受案状态
        if (!"3".equals(vo.getCaseStatus()) && !ExecuteStateEnum.ACCEPT_CASE.getCode().equals(vo.getExecuteState())) {
            LocalDate handleDeadlineEndDate = vo.getExecutionDeadlineTime().toLocalDate();
            //组装办案期限状态描述
            Map<String, String> statusMap = assembleCaseHandleDeadlineStatusInfo(LocalDate.now(), handleDeadlineEndDate);
            for (String key : statusMap.keySet()) {
                String value = statusMap.get(key);
                vo.setExecuteHandleDeadlineStatus(key);
                vo.setExecuteHandleDeadlineStatusShowColor(value);
            }
        }
        //当事人
        List<ExecutePartyInfoVo> executePartyInfoList = executePartyInfoService.getExecutePartyInfo(executeDetailDto.getExecuteId());
        for (ExecutePartyInfoVo executePartyInfoVo : executePartyInfoList) {
            executePartyInfoVo.setPartyTypeName(PartyTypeEnum.getValueByCode(executePartyInfoVo.getPartyType()));
            executePartyInfoVo.setPartyIdentityTypeName(CourtCertTypeEnum.getValueByCode(executePartyInfoVo.getPartyIdentityType()));
        }
        vo.setCasePartiesReasonType("3");
        if (executePartyInfoList.size() > 0) {
            vo.setPartyInfoList(executePartyInfoList);
            if (executePartyInfoList.size() > 1) {
                //vo.setCasePartiesReasonType("3");
                vo.setPartyName(executePartyInfoList.get(0).getPartyName() + "等" + executePartyInfoList.size() + "个");
            } else {
                //vo.setCasePartiesReasonType("1");
                vo.setPartyName(executePartyInfoList.get(0).getPartyName());
            }
        }
        //审批表列表
        //获取案件关联文书
        String isShowButton = Constant.STRING_1;
        ExecuteStageLinkRelateDocumentQueryDto query = new ExecuteStageLinkRelateDocumentQueryDto();
        query.setExecuteId(executeDetailDto.getExecuteId());
        List<ExecuteStageLinkRelateDocumentVo> executeStageLinkRelateDocumentList
                = executeDocumentRecordService.getExecuteStageLinkRelateDocumentInfo(query);
        for (ExecuteStageLinkRelateDocumentVo relVo : executeStageLinkRelateDocumentList) {
            if (Constant.STRING_1.equals(relVo.getIsNeedApproval()) && DocumentStatusEnum.CHECKING.getCode().equals(relVo.getDocumentApprovalStatus())) {
                isShowButton = Constant.STRING_0;
            }
        }
        //已结案状态不显示
        if ("3".equals(executeMainInfo.getCaseStatus())) {
            isShowButton = Constant.STRING_0;
        }
        vo.setIsShowButton(isShowButton);//审批状态，不展示按钮
        //当前阶段可选文书列表
        List<ExecuteStageLinkRelateDocumentVo> executeDetailOperateDocInfoVoList = new ArrayList<>();
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andLike("applyGroup", "%CZFL%");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        configBusiParamDocumentInfos.forEach(configBusiParamDocumentInfo -> {
            ExecuteStageLinkRelateDocumentVo executeDetailOperateDocInfoVo = new ExecuteStageLinkRelateDocumentVo();
            executeDetailOperateDocInfoVo.setDocumentKindCode(configBusiParamDocumentInfo.getDocumentKindCode());
            executeDetailOperateDocInfoVo.setDocumentKindName(configBusiParamDocumentInfo.getDocumentKindName());
            executeDetailOperateDocInfoVo.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
            executeDetailOperateDocInfoVo.setIsNeedApproval(configBusiParamDocumentInfo.getIsApprove());
            executeDetailOperateDocInfoVo.setAllRelationDocCatalogCodeList(null);
            executeDetailOperateDocInfoVo.setCaseDocumentTypeFlag(null);
            if("QZZXGG".equals(configBusiParamDocumentInfo.getDocumentKindCode())){
                executeDetailOperateDocInfoVo.setCaseDocumentTypeFlag(Constant.STRING_1);
            }
            executeDetailOperateDocInfoVo.setExecuteId(executeDetailDto.getExecuteId());
            List<CasePartyRelateDocInfoVo> casePartiesKeyInfoVos = new ArrayList<>();
            CasePartyRelateDocInfoVo casePartyRelateDocInfo;
            for (ExecutePartyInfo party : executePartyInfoList) {
                casePartyRelateDocInfo = new CasePartyRelateDocInfoVo();
                BeanUtils.copyProperties(party, casePartyRelateDocInfo);
                casePartyRelateDocInfo.setPartyId(party.getId());
                casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.NO.getCode());
                //查看该当事人是否已经添加该文书
                Example queryCountExample = new Example(ExecuteDocumentRecord.class);
                queryCountExample.createCriteria().andEqualTo("executeId", executeDetailDto.getExecuteId())
                        .andEqualTo("documentCatalogCode", configBusiParamDocumentInfo.getDocumentCatalogCode())
                        .andEqualTo("partyId", casePartyRelateDocInfo.getPartyId())
                        //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                        .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
                int count = executeDocumentRecordMapper.selectCountByExample(queryCountExample);
                if (count > 0) {
                    casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.YES.getCode());
                }
                casePartyRelateDocInfo.setIsAddedThisDocName(YesOrNoEnum
                        .getValueByCode(casePartyRelateDocInfo.getIsAddedThisDoc()));
                casePartiesKeyInfoVos.add(casePartyRelateDocInfo);
            }
            executeDetailOperateDocInfoVo.setDocRelatePartiesList(casePartiesKeyInfoVos);

            //查询已生成的文书信息
            Example docExample = new Example(ExecuteDocumentRecord.class);
            docExample.createCriteria().andEqualTo("executeId", executeDetailDto.getExecuteId()).
                    andEqualTo("documentCatalogCode", executeDetailOperateDocInfoVo.getDocumentCatalogCode());
            List<ExecuteDocumentRecord> executeDocumentRecords = executeDocumentRecordMapper.selectByExample(docExample);
            if (executeDocumentRecords != null && executeDocumentRecords.size() > 0) {
                BeanUtils.copyProperties(executeDocumentRecords.get(0), executeDetailOperateDocInfoVo);
            }
            executeDetailOperateDocInfoVo.setDocumentLinkObjectType(configBusiParamDocumentInfo.getDocumentLinkObjectType());
            //审批表
            /*if(Constant.STRING_1.equals(configBusiParamDocumentInfo.getDocumentType())){
                caseDetailOperateApprovalTableInfoVoList.add(caseDetailOperateDocInfoVo);
                //caseDetailOperateDocInfoVo.setDocIsExistsAndWaitToSignRelatedPartyIdList();
            }*/
            //法律文书
            if (Constant.STRING_2.equals(configBusiParamDocumentInfo.getDocumentType())
                    && configBusiParamDocumentInfo.getApplyGroup().contains(executeMainInfo.getExecuteState())) {
                //审批和审批后不能进行操作
                if(!DocumentStatusEnum.CHECK_END.getCode().equals(executeDetailOperateDocInfoVo.getDocumentApprovalStatus()) &&
                        !DocumentStatusEnum.CHECKING.getCode().equals(executeDetailOperateDocInfoVo.getDocumentApprovalStatus())){//已审批
                    executeDetailOperateDocInfoVoList.add(executeDetailOperateDocInfoVo);
                }
            }
        });
        vo.setExecuteDetailOperateDocInfoVoList(executeDetailOperateDocInfoVoList);

        //阶段流转信息
        List<ExecuteDetailStageInfoVo> executeDetailStageInfoList = getExecuteDetailStageInfo(executeDetailDto.getExecuteId());
        vo.setExecuteStageInfoList(executeDetailStageInfoList);
        /*
            案件总耗时:已结案的展示，结案时间-指派时间；未结案的展示当前时间-立案时间
         */
        ExecuteCluHandoutRecord handoutRecord = executeCluHandoutRecordService.selectByExecuteId(executeDetailDto.getExecuteId());
        if (handoutRecord != null) {
            ExecuteCluHandoutRecord executeCluHandoutRecord= executeCluHandoutRecordService.selectByExecuteId(executeDetailDto.getExecuteId());
            if(executeCluHandoutRecord !=null){
                vo.setExecutionStartTime(DateUtil.dateToLocalDateTime(executeCluHandoutRecord.getCluAssignTime()));
            }
            Date calculateStartTime = executeCluHandoutRecord.getCluAssignTime();
            if (!ObjectUtils.isEmpty(calculateStartTime)) {
                Date closeCaseTime = executeMainInfo.getCloseCaseTime();
                LocalDateTime calculateEndTime;
                if (ObjectUtils.isEmpty(closeCaseTime)) {
                    calculateEndTime = LocalDateTime.now();
                }else{
                    calculateEndTime = DateUtil.dateToLocalDateTime(closeCaseTime);
                }
                //HashMap<String, String> map = DateUtil.calculateTimeIntervalInfo(DateUtil.dateToLocalDateTime(calculateStartTime), calculateEndTime, false);
                HashMap<String, String> map = DateUtil.calculateTimeIntervalInfoDay(DateUtil.dateToLocalDateTime(calculateStartTime), calculateEndTime, false);
                String caseTotalTime = map.get("showTime");
                vo.setExecuteTotalTime(caseTotalTime);
            }
        }
        return vo;
    }

    @Override
    public ExecuteApprovalVo getExecuteApprovalDetail(ExecuteDetailDto executeDetailDto) {
        String executeId = executeDetailDto.getExecuteId();
        ExecuteApprovalVo executeApprovalVo = executeMainInfoMapper.selectExecuteApprovalDetail(executeId);
        List<ExecutePartyNameVo> executePartyNameVos = executePartyInfoMapper.selectPartyName(executeId);
        if (ObjectUtil.isNotEmpty(executePartyNameVos)) {
            for (ExecutePartyNameVo executePartyNameVo : executePartyNameVos) {
                executePartyNameVo.setPartyIdentityType(CourtCertTypeEnum.getValueByCode(executePartyNameVo.getPartyIdentityType()));
                executePartyNameVo.setLegalCertType(CourtCertTypeEnum.getValueByCode(executePartyNameVo.getLegalCertType()));
            }
            // 多当事人
            if (executePartyNameVos.size() > 1) {
                executeApprovalVo.setPartyName(executePartyNameVos.get(0).getPartyName() + "等" + executePartyNameVos.size() + "个");
                executeApprovalVo.setPartyType("multitude");
            } else {
                executeApprovalVo.setPartyName(executePartyNameVos.get(0).getPartyName());
                executeApprovalVo.setPartyIdentityCode(executePartyNameVos.get(0).getPartyIdentityCode());
                executeApprovalVo.setPartyType(executePartyNameVos.get(0).getPartyType());
            }
        }
        // 当事人信息
        executeApprovalVo.setExecutePartyNameVos(executePartyNameVos);
        String decisionNumber = executeApprovalVo.getDecisionNumber();
        CaseDocumentRecord caseDocumentRecord = new CaseDocumentRecord();
        caseDocumentRecord.setDocumentNumber(decisionNumber);
        CaseDocumentRecord caseDocumentRecord1 = caseDocumentRecordMapper.selectOne(caseDocumentRecord);
        if (!ObjectUtils.isEmpty(caseDocumentRecord1)) {
            // 行政处罚决定书编号存在本系统
            executeApprovalVo.setIsDecision(Constant.STRING_1);
            executeApprovalVo.setCaseType(caseMainInfoMapper.selectByPrimaryKey(caseDocumentRecord1.getCaseId()).getCaseType());
            executeApprovalVo.setCaseId(caseDocumentRecord1.getCaseId());
        }
        return executeApprovalVo;
    }

    /**
     * 描述：组装办案期限状态信息
     *
     * @param compareStartDate 比对开始日期
     * @param compareEndDate   比对结束日期
     * @return {@link Map<String,String> } 办案期限状态信息(描述对应颜色标识)
     * @author xiangyuyu
     * @date 2022-02-22 16:14
     */
    private Map<String, String> assembleCaseHandleDeadlineStatusInfo(LocalDate compareStartDate, LocalDate compareEndDate) {
        String status = "已到期";
        Map<String, String> map = new HashMap<>(2);

        String color = "orange";
        long count = compareEndDate.toEpochDay() - compareStartDate.toEpochDay();
        if (count > 0) {
            status = "剩" + count + "天";
            color = "green";
        } else if (count < 0) {
            status = "超" + (-count) + "天";
            color = "red";
        }
        map.put(status, color);
        return map;
    }

    @Override
    public List<ExecuteStageDocumentInfoVo> getExecuteStageDocumentInfo(ExecuteStageDocumentQueryDto queryDto) {
        List<ExecuteStageDocumentInfoVo> voList = new ArrayList<>();
        ExecuteMainInfo executeMainInfo = this.getByExecuteId(queryDto.getExecuteId());
        //受案阶段-查询法院推过来的数据-民事裁定书和行政处罚决定书
        ExecuteStageDocumentInfoVo saStageDocumentInfoVo = new ExecuteStageDocumentInfoVo();
        saStageDocumentInfoVo.setExecuteStageName(ExecuteStateEnum.ACCEPT_CASE.getDes());
        saStageDocumentInfoVo.setExecuteStageCode(ExecuteStateEnum.ACCEPT_CASE.getCode());
        List<ExecuteStageLinkRelateDocumentVo> saDocList = executeFilesRecordService.selectExecuteFiles(queryDto.getExecuteId());
        saStageDocumentInfoVo.setExecuteStageRelateDocumentList(saDocList);
        voList.add(saStageDocumentInfoVo);

        //关联文书
        //List<CaseStageLinkRelateDocumentVo> relatedDocList = caseRelatedDocumentRecordService.getRelatedDocInfoToCaseStageLinkRelateDocument(caseId);
        //线下上传文书
        //List<CaseStageLinkRelateDocumentVo> offlineDocList = caseOfflineDocumentRecordService.getOfflineDocInfoToCaseStageLinkRelateDocument(caseId);

        //当事人
        List<ExecutePartyInfoVo> executePartyInfoList = executePartyInfoService.getExecutePartyInfo(queryDto.getExecuteId());
        //案件阶段查询
        ConfigDictionaryInfoQueryDto dto = new ConfigDictionaryInfoQueryDto();
        dto.setIsEffective(Constant.STRING_1);
        dto.setDicFieldCode(Constant.STRING_EXECUTE_STAGE);
        List<ConfigDictionaryInfoVo> configDictionaryInfoVos = configDictionaryInfoService.getConfigDictionaryList(dto);
        if (null != configDictionaryInfoVos && configDictionaryInfoVos.size() > 0) {
            for (ConfigDictionaryInfoVo configDictionaryInfoVo : configDictionaryInfoVos) {
                String caseStageCode = configDictionaryInfoVo.getDicCode();
                ExecuteStageDocumentInfoVo vo = new ExecuteStageDocumentInfoVo();
                vo.setExecuteStageCode(configDictionaryInfoVo.getDicCode());
                vo.setExecuteStageName(configDictionaryInfoVo.getDicName());
                ExecuteStageLinkRelateDocumentQueryDto query = new ExecuteStageLinkRelateDocumentQueryDto();
                query.setExecuteId(queryDto.getExecuteId());
                query.setExecuteStageCode(configDictionaryInfoVo.getDicCode());
                if (Constant.STRING_1.equals(queryDto.getDocType())) {
                    query.setDocumentRecordStatus(Constant.STRING_1);
                } else if (Constant.STRING_0.equals(queryDto.getDocType())) {
                    query.setDocumentRecordStatus(Constant.STRING_3);
                }
                List<ExecuteStageLinkRelateDocumentVo> executeStageLinkRelateDocumentList
                        = executeDocumentRecordService.getExecuteStageLinkRelateDocumentInfo(query);
                List<ExecuteStageLinkRelateDocumentVo> filterExecuteStageLinkRelateDocumentList = new ArrayList<>();
                for (ExecuteStageLinkRelateDocumentVo executeStageLinkRelateDocumentVo : executeStageLinkRelateDocumentList) {
                    if (executeStageLinkRelateDocumentVo.getDocumentKindCode().equals(Constant.STRING_KIND_CODE_SDHZ)) {
                        continue;
                    }
                    if (executeStageLinkRelateDocumentVo.getDocumentKindCode().equals(Constant.STRING_KIND_CODE_LHTZS)) {
                        //领回通知书
                        executeStageLinkRelateDocumentVo.setIsMultiple(Constant.STRING_0);
                    }else{
                        executeStageLinkRelateDocumentVo.setIsMultiple(executePartyInfoList != null && executePartyInfoList.size()>0 ? Constant.STRING_1 : Constant.STRING_0);
                    }

                    String documentCatalogCode = executeStageLinkRelateDocumentVo.getDocumentCatalogCode();
                    ExecuteAppendixRecord queryAttachment = new ExecuteAppendixRecord();
                    queryAttachment.setExecuteId(queryDto.getExecuteId());
                    queryAttachment.setDocumentCatalogCode(documentCatalogCode);
                    //关联当事人
                    if(StringUtils.isNotBlank(executeStageLinkRelateDocumentVo.getPartyId()) && executePartyInfoList.size()>1){
                        ExecutePartyInfo executePartyInfo = executePartyInfoMapper.selectByPrimaryKey(executeStageLinkRelateDocumentVo.getPartyId());
                        executeStageLinkRelateDocumentVo.setDocumentCatalogName(executeStageLinkRelateDocumentVo.getDocumentCatalogName()+"("+executePartyInfo.getPartyName()+")");
                        queryAttachment.setPartyId(executeStageLinkRelateDocumentVo.getPartyId());
                    }
                    List<ExecuteAppendixRecord> appendixRecords = executeAppendixRecordMapper.select(queryAttachment);
                    List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                    appendixRecords.forEach(a -> {
                        DocumentRelateAttachmentVo attachmentVo = new DocumentRelateAttachmentVo();
                        attachmentVo.setAttachmentId(a.getId());
                        attachmentVo.setAttachmentId(a.getAppendixName());
                        attachmentVo.setAttachmentUrl(a.getAppendixUrl());
                        attachmentVo.setAttachmentType(AttachmentTypeEnum.getValueByCode(a.getAppendixTypeId()));
                        attachmentVo.setCreateTime(DateUtil.dateToLocalDateTime(a.getUploadTime()));
                        attachmentVo.setAttachmentTitle(a.getAppendixName());
                        attachmentVo.setCreateUserName(a.getUploadUserName());
                        documentRelateAttachmentList.add(attachmentVo);
                    });
                    executeStageLinkRelateDocumentVo.setDocumentRelateAttachmentCount(documentRelateAttachmentList == null ? 0 : documentRelateAttachmentList.size());
                    executeStageLinkRelateDocumentVo.setDocumentRelateAttachmentList(documentRelateAttachmentList);
                    //根据文书目录编码查询关联文书
                    filterExecuteStageLinkRelateDocumentList.add(executeStageLinkRelateDocumentVo);


                }

                vo.setExecuteStageRelateDocumentList(filterExecuteStageLinkRelateDocumentList);
                voList.add(vo);
            }
        }
        return voList;
    }

    /**
     * 【V1.0.0】描述：获取裁执分离-阶段信息
     *
     * @param executeId 案件id
     * @return {@link List<ExecuteDetailStageInfoVo>} 案件详情-阶段信息
     * @author wuzhihui
     * @date 2022-02-23 21:37
     */
    @Override
    public List<ExecuteDetailStageInfoVo> getExecuteDetailStageInfo(String executeId) {
        ConfigDictionaryInfoQueryDto queryDto = new ConfigDictionaryInfoQueryDto();
        queryDto.setDicFieldCode(Constant.STRING_EXECUTE_STAGE);
        queryDto.setIsEffective(YesOrNoEnum.YES.getCode());
        List<ConfigDictionaryInfoVo> stageList = configDictionaryInfoService.getConfigDictionaryList(queryDto);
        if (ObjectUtils.isEmpty(stageList)) {
            throw new BusinessException("未配置阶段数据字典");
        }
        ExecuteMainInfo executeMainInfo = getByExecuteId(executeId);
        List<ExecuteDetailStageInfoVo> executeDetailStageInfoList = new ArrayList<>();
        ExecuteFlowRecordRequest flowRecordRequest = new ExecuteFlowRecordRequest();
        flowRecordRequest.setExecuteId(executeId);
        List<ExecuteFlowRecord> executeFlowRecords = executeFlowRecordService.getFlowRecordList(flowRecordRequest);
        //组装各阶段名信息
        for (ConfigDictionaryInfoVo e : stageList) {
            ExecuteDetailStageInfoVo stageInfo = new ExecuteDetailStageInfoVo();
            stageInfo.setStageId(e.getDicCode());
            stageInfo.setStageName(e.getDicName());
            stageInfo.setStageIsFinish(YesOrNoEnum.NO.getCode());
            stageInfo.setStageIsFinishName(YesOrNoEnum.NO.getDes());
            stageInfo.setIsCurrentStageCode(YesOrNoEnum.NO.getCode());
            stageInfo.setIsCurrentStageName(YesOrNoEnum.NO.getDes());
            if (e.getDicCode().equals(executeMainInfo.getExecuteState())) {
                stageInfo.setIsCurrentStageCode(YesOrNoEnum.YES.getCode());
                stageInfo.setIsCurrentStageName(YesOrNoEnum.YES.getDes());
            }
            for (ExecuteFlowRecord executeFlowRecord : executeFlowRecords) {
                if (e.getDicCode().equals(executeFlowRecord.getFlowStageCode())) {
                    if (executeFlowRecord.getFlowStartTime() != null) {
                        stageInfo.setShowTime(DateUtil.dateToLocalDateTime(executeFlowRecord.getFlowStartTime()));
                    }
                    stageInfo.setStageIsFinish(YesOrNoEnum.YES.getCode());
                    stageInfo.setStageIsFinishName(YesOrNoEnum.YES.getDes());
                }
            }
            executeDetailStageInfoList.add(stageInfo);
        }
        return executeDetailStageInfoList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ExecuteCloseVoDto closeExecute(ExecuteCloseSaveDto saveDto) {
        ExecuteCloseVoDto result = new ExecuteCloseVoDto();
        result.setExecuteId(saveDto.getExecuteId());
        ExecuteMainInfo executeMainInfo = getByExecuteId(saveDto.getExecuteId());
        if (!ExecuteStateEnum.CASE_CLOSED.getCode().equals(executeMainInfo.getExecuteState())) {
            throw new BusinessException("非结案阶段不允许结案!");
        }
        if (ExecuteStatusEnum.END_EXECUTE.getIndex().equals(executeMainInfo.getCaseStatus())) {
            throw new BusinessException("案件已完结!");
        }
        //结案日期不能早于执行完成日期
        ExecuteCompleteRecord completeRecord = executeCompleteRecordService.getExecuteCompleteRecordByExecuteId(saveDto.getExecuteId());
        if(saveDto.getCloseCaseTime().compareTo(completeRecord.getExecuteFinishDate())<0){
            throw new BusinessException("结案日期不能早于执行完成日期!");
        }
        //查询是否有在审批中的文书,有的话不许结案
        Example queryCountExample = new Example(ExecuteDocumentRecord.class);
        queryCountExample.createCriteria().andEqualTo("executeId", saveDto.getExecuteId())
                .andEqualTo("documentAuditStatus", "pending")
                //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
        int count = executeDocumentRecordMapper.selectCountByExample(queryCountExample);

        if (count > 0) {
            throw new BusinessException("有待审批的文书!");
        }
        Example updateExample = new Example(ExecuteMainInfo.class);
        updateExample.createCriteria().
                andEqualTo("executeId", saveDto.getExecuteId());
        executeMainInfo.setCloseCaseTime(saveDto.getCloseCaseTime());
        executeMainInfo.setCloseCaseDesc(saveDto.getCloseCaseDesc());
        executeMainInfo.setDemolitionArea(saveDto.getDemolitionArea());
        int updateCount = executeMainInfoMapper.updateByExampleSelective(executeMainInfo, updateExample);
        //生成文书
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(null, "ZXHZ");
        ExecuteDocCommonOperateSaveDto docSaveDto = new ExecuteDocCommonOperateSaveDto();
        docSaveDto.setExecuteId(saveDto.getExecuteId());
        docSaveDto.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
        HashMap<String, Object> dataMap = new HashMap<>();

        SysDepartParam sysDepartParamBy = sysDepartParamService.getSysDepartParamByOrgCode(executeMainInfo.getHandleOrgCode(),"");
        dataMap.put("orgStandardName",sysDepartParamBy.getOrgStandardName());
        dataMap.put("rulingCourt",executeMainInfo.getRulingCourt());
        dataMap.put("ruleNumber",executeMainInfo.getRuleNumber());
        dataMap.put("executeDate", DateFormatUtils.format(saveDto.getCloseCaseTime(), "yyyy年MM月dd日"));
        dataMap.put("orgStandardNameSeal",sysDepartParamBy.getOrgStandardName());
        dataMap.put("demolitionArea",saveDto.getDemolitionArea());
        docSaveDto.setDataMap(dataMap);
        result.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
        Map<String, Object> docResultMap = executeDocCommonOperateService.saveDocInfo(docSaveDto);
        String status = MapUtils.getString(docResultMap, "success", "");
        String msg = MapUtils.getString(docResultMap, "msg", "");
        if (!"true".equals(status)) {
            logger.info("----------文书生成公共服务saveDocInfo------报错---" + docResultMap);
            throw new BusinessException(msg);
        }
        ExecuteDocumentRecord executeDocumentRecord = executeDocumentRecordService.getExecuteDocumentRecord(saveDto.getExecuteId(), configBusiParamDocumentInfo.getDocumentCatalogCode(), null);
        if (executeDocumentRecord != null) {
            result.setDocumentId(executeDocumentRecord.getId());
            result.setDocumentUrl(executeDocumentRecord.getDocumentUrl());
        }

        if (updateCount > 0) {
            //处理结案附件信息
            dealCloseAppendix(saveDto);
            //处理流转日志
            executeFlowRecordService.dealCurrentAndNextExecuteFlowRecord(saveDto.getExecuteId(), executeMainInfo.getExecuteState(), null);
        }
        return result;
    }

    @Override
    public ExecuteCloseInfoVo getCloseExecuteInfo(ExecuteCloseRequestDto requestDto) {
        ExecuteMainInfo executeMainInfo = getByExecuteId(requestDto.getExecuteId());
        ExecuteCloseInfoVo result = new ExecuteCloseInfoVo();
        BeanUtils.copyProperties(executeMainInfo, result);
        result.setCloseCaseTime(executeMainInfo.getCloseCaseTime());
        //查询附件信息
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(null, "ZXHZ");
        ExecuteAppendixRecord queryAttachment = new ExecuteAppendixRecord();
        queryAttachment.setExecuteId(requestDto.getExecuteId());
        queryAttachment.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
        List<ExecuteAppendixRecord> appendixRecords = executeAppendixRecordMapper.select(queryAttachment);
        List<AppendixDto> appendixList = new ArrayList<>();
        for (ExecuteAppendixRecord appendixRecord : appendixRecords) {
            AppendixDto appendixDto = new AppendixDto();
            appendixDto.setAppendixName(appendixRecord.getAppendixName());
            appendixDto.setAppendixType(appendixRecord.getAppendixType());
            appendixDto.setAppendixTypeId(appendixRecord.getAppendixTypeId());
            appendixDto.setAppendixUrl(appendixRecord.getAppendixUrl());
            appendixList.add(appendixDto);
        }
        result.setAppendixList(appendixList);
        //查询文书id
        return result;
    }

    /**
     * 处理结案附件信息
     *
     * @param: [executeId, appendixList]
     * @return: void
     * @Author: wuzhihui
     * @Date: 2022/09/06
     */
    private void dealCloseAppendix(ExecuteCloseSaveDto saveDto) {
        UserDTO userDTO = UserUtil.getUserInfo();
        if (userDTO == null) {
            throw new BusinessException("登录信息失效或未登录!");
        }
        if (saveDto.getAppendixList() != null && saveDto.getAppendixList().size() > 0) {
            for (AppendixDto appendixDto : saveDto.getAppendixList()) {
                ExecuteAppendixRecord appendixRecord = new ExecuteAppendixRecord();
                appendixRecord.setId(StringUtils.uuid());
                appendixRecord.setExecuteStageCode(ExecuteStateEnum.CASE_CLOSED.getCode());
                appendixRecord.setExecuteStageName(ExecuteStateEnum.CASE_CLOSED.getDes());
                //设置强制执行完毕
                ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(null, "ZXHZ");
                appendixRecord.setDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
                appendixRecord.setAppendixTypeId(appendixDto.getAppendixTypeId());
                appendixRecord.setAppendixUrl(appendixDto.getAppendixUrl());
                appendixRecord.setAppendixName(appendixDto.getAppendixName());
                appendixRecord.setExecuteId(saveDto.getExecuteId());
                appendixRecord.setId(BaseUtil.createUid());
                appendixRecord.setUploadTime(new Date());
                appendixRecord.setUploadUserId(userDTO.getUserId().toString());
                appendixRecord.setUploadUserName(userDTO.getRealName());
                appendixRecord.setIsDelete(Constant.STRING_0);
                appendixRecord.setAppendixStatus(Constant.STRING_1);
                executeAppendixRecordMapper.insertSelective(appendixRecord);
            }
        }
    }

    /**
     * 描述: 将结案信息推送给法院
     *
     * @param requestDto 数据推送给法院的参数对象
     * @return java.lang.Boolean
     * @author zhanghongqiang
     * @Date 2022/9/13
     */
    @Override
    public Boolean closingCallback(ExecuteDataRequestDto requestDto) {
        ExecuteCallbackRecord executeCallbackRecord =new ExecuteCallbackRecord();
        executeCallbackRecord.setId(StringUtils.uuid());
        executeCallbackRecord.setExecuteId(requestDto.getExecuteId());
        executeCallbackRecord.setRequestParam(requestDto.toString());
        try {
            String token = caseNonLitigationExecuteRecordService.getBearerToken("");
            if (ObjectUtil.isEmpty(token)) {
                executeCallbackRecord.setIsSuccess(Constant.STRING_0);
                executeCallbackRecord.setErrorInfo("获取法院方token失败");
                executeCallbackRecordMapper.insertSelective(executeCallbackRecord);
                throw new BusinessException("获取法院方token失败");
            }
            Map<String, Object> paramMap = new HashMap<>(16);
            paramMap.put("executeId", requestDto.getExecuteId());
            paramMap.put("executeOfficeName", requestDto.getExecuteOfficeName());
            paramMap.put("executeDate", requestDto.getExecuteDate());
            paramMap.put("executePerson", requestDto.getExecutePerson());
            paramMap.put("executeConclusion", requestDto.getExecuteConclusion());
            paramMap.put("executeCycle", requestDto.getExecuteCycle());
            paramMap.put("ruleNumber", requestDto.getRuleNumber());
            String result = HttpUtils.doHttpPostWithToken(url + czflJahd, "Bearer " + token, paramMap);
            if (StringUtils.isNotBlank(result)) {
                JSONObject jsonObject = JSONObject.parseObject(result);
                String resultInfo = jsonObject.toString();
                if (ObjectUtil.isNotEmpty(jsonObject.get("code"))) {
                    if (Constant.STRING_200.equals(jsonObject.getString("code"))) {
                        String msg = jsonObject.getString("msg");
                        if ("结案回调成功".equals(msg)) {
                            logger.info("结案数据推送法院成功 Successfully,result:{}", resultInfo);
                            executeCallbackRecord.setIsSuccess(Constant.STRING_1);
                            executeCallbackRecord.setErrorInfo(resultInfo);
                            executeCallbackRecordMapper.insertSelective(executeCallbackRecord);
                            return true;
                        }
                    } else {
                        logger.info("结案数据推送法院失败 Fail,result:{}", resultInfo);
                        executeCallbackRecord.setIsSuccess(Constant.STRING_0);
                        executeCallbackRecord.setErrorInfo(resultInfo);
                        executeCallbackRecordMapper.insertSelective(executeCallbackRecord);
                        return false;
                    }
                } else {
                    logger.info("结案数据推送法院失败 Fail ,result:{}", jsonObject.toString());
                    return false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            executeCallbackRecord.setIsSuccess(Constant.STRING_0);
            executeCallbackRecord.setErrorInfo(e.getMessage());
            executeCallbackRecordMapper.insertSelective(executeCallbackRecord);
            logger.info("结案数据推送法院失败 Fail ,result:{}", e.getMessage());
        }
        return false;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> savePunishExecuteInfo(ExecutePunishActionDto executePunishActionDto) {
        String executeId = executePunishActionDto.getExecuteId();
        //获取案件信息
        ExecuteMainInfo executeMainInfo  = getByExecuteId(executeId);
        if(PREVENT_DEAL_CASE_STATUS_LIST.contains(executeMainInfo.getExecuteState())){
            throw new BusinessException("当前案件状态不允许进行该操作");
        }
        String partyId = executePunishActionDto.getPartyId();
        //String isShowPartiesSelector = caseMainInfoService.validateIsShowPartiesSelector(caseMainInfo,null);
        Map<String, String> map = executePartyInfoService.getExecutePartyIdNameInfo(executeId);
        /*if (YesOrNoEnum.YES.getCode().equals(isShowPartiesSelector)
                && ObjectUtils.isEmpty(partyId)) {
            throw new BusinessException("多当事人分别处罚时请指定当事人id");
        }*/

        String allPartyIds = map.get("partyId");
        if(ObjectUtils.isEmpty(partyId)){
            partyId  = allPartyIds;
        }
        String partyName = map.get("partyName");
        //获取该当事人的名称
        String[] idArr = partyId.split(",");
        String[] nameArr = partyName.split(",");
        for (int i = 0; i < idArr.length; i++) {
            if(partyId.equals(idArr[i])){
                partyName = nameArr[i];
            }
        }

        //String partiesReasonType = caseMainInfo.getCasePartiesReasonType();

        int upr;
        Example example;
        Date executeFinishDate = DateUtil.strToDate(executePunishActionDto.getPunishDate(),"yyyy-MM-dd");
        example = new Example(ExecuteCompleteRecord.class);
        example.createCriteria().andEqualTo("executeId", executeId);
        ExecuteCompleteRecord executeCompleteRecord;
        boolean isInsert = true;
        List<ExecuteCompleteRecord> executeCompleteRecordList = executeCompleteRecordMapper.selectByExample(example);
        if(ObjectUtils.isEmpty(executeCompleteRecordList) || executeCompleteRecordList.size() == 0){
            isInsert = true;
            executeCompleteRecord = new ExecuteCompleteRecord();
            executeCompleteRecord.setId(StringUtils.uuid());
            executeCompleteRecord.setExecuteId(executeId);
        }else{
            executeCompleteRecord = executeCompleteRecordList.get(0);
        }
        executeCompleteRecord.setExecuteFinishDate(executeFinishDate);
        UserDTO userInfo = UserUtil.getUserInfo();
        if(userInfo==null){
            throw new BusinessException("请先登录!");
        }
        executeCompleteRecord.setCreateUserId(String.valueOf(userInfo.getUserId()));
        executeCompleteRecord.setCreateUserName(userInfo.getRealName());
        executeCompleteRecord.setCreateTime(new Date());
        // 存为中文
        executeCompleteRecord.setExecuteWay(executePunishActionDto.getPunishType());
        if (AuditStatusConstant.CONSCIOUS_EXECUTE.equals(executePunishActionDto.getPunishType())) {
            executeCompleteRecord.setExecuteWay("自觉履行");
        }
        if (AuditStatusConstant.ENFORCE_EXECUTE.equals(executePunishActionDto.getPunishType())) {
            executeCompleteRecord.setExecuteWay("强制执行");
        }
        executeCompleteRecord.setExecuteConditionDesc(executePunishActionDto.getPunishActionDesc());
        if(isInsert){
            upr = executeCompleteRecordMapper.insertSelective(executeCompleteRecord);
        }else{
            upr = executeCompleteRecordMapper.updateByPrimaryKeySelective(executeCompleteRecord);
        }
        String documentCatalogCode = "ZXQKHCJL90AC9";
        //保存附件
        //执行情况凭证文件列表
        List<CaseAttachmentInfoSaveDto> executeProofFileList = executePunishActionDto.getExecuteProofFileList();
        if (ObjectUtils.isEmpty(executeProofFileList) || executeProofFileList.size() == 0) {
            throw new BusinessException("未指定执行情况凭");
        }
        //现场核查记录文件列表
        List<CaseAttachmentInfoSaveDto> realPlaceCheckRecordFileList = executePunishActionDto.getRealPlaceCheckRecordFileList();

        List<CaseAttachmentInfoSaveDto> caseAttachmentInfoList = new ArrayList<>();
        caseAttachmentInfoList.addAll(executeProofFileList);
        if (!ObjectUtils.isEmpty(realPlaceCheckRecordFileList)) {
            caseAttachmentInfoList.addAll(realPlaceCheckRecordFileList);
        }
        if (!ObjectUtils.isEmpty(executePunishActionDto.getOtherFileList())) {
            caseAttachmentInfoList.addAll(executePunishActionDto.getOtherFileList());
        }
        //String finalPartyId = partyId;
        caseAttachmentInfoList.forEach(e -> {
            ExecuteAppendixRecord executeAppendixRecord = new ExecuteAppendixRecord();
            String attachmentId = e.getId();
            if (ObjectUtils.isEmpty(attachmentId)) {
                BeanUtils.copyProperties(e, executeAppendixRecord);
                executeAppendixRecord.setId(BaseUtil.createUid());
                executeAppendixRecord.setExecuteId(executeId);
                executeAppendixRecord.setExecuteStageName(ExecuteStateEnum.getValueByCode(executeMainInfo.getExecuteState()));
                executeAppendixRecord.setExecuteStageCode(executeMainInfo.getExecuteState());
                executeAppendixRecord.setDocumentCatalogCode(documentCatalogCode);
                if (!ObjectUtils.isEmpty(userInfo)) {
                    executeAppendixRecord.setUploadUserId(userInfo.getUserId() + "");
                    executeAppendixRecord.setUploadUserName(userInfo.getRealName());
                }
                executeAppendixRecord.setUploadTime(new Date());
                String appendixTypeId = executeAppendixRecord.getAppendixTypeId();
                if (ObjectUtils.isEmpty(appendixTypeId)) {
                    throw new BusinessException("未指定附件类型id【" + executeAppendixRecord.getAppendixName() + "】");
                }
                String appendixUrl = executeAppendixRecord.getAppendixUrl();
                if (ObjectUtils.isEmpty(appendixUrl)) {
                    throw new BusinessException("未指定附件地址【" + executeAppendixRecord.getAppendixName() + "】");
                }
                //executeAppendixRecord.setPartyId(finalPartyId);
                executeAppendixRecordMapper.insertSelective(executeAppendixRecord);
            }
        });
        //执行情况记录生成
        generateExecuteConditionRecord(executeId, realPlaceCheckRecordFileList, executeProofFileList,null,partyName);
        Map<String, Object> result = new HashMap<>(8);
        if (upr == 1) {
            /*if (!caseMainInfoService.checkCaseIsPartiesPartPunish(null,caseMainInfo)){
                partyId = null;
            }*/
            //result = executeFlowRoll(caseId,partyId,"ZXQKHCJL29F3F");
            result.put("success", "true");
            result.put("msg", "成功！");
        } else {
            logger.info("savePunishExecuteInfo savePunishExecuteInfo error");
            throw new BusinessException("保存执行完毕信息时出现异常");
        }
        return result;
    }
    /**
     * 描述：生成执行情况核查记录
     *
     * @param executeId                    裁执分离id
     * @param realPlaceCheckRecordFileList 现场核查记录文件列表
     * @param paymentProofFileList         缴款凭证文件列表
     * @param partyId                      当事人id
     * @param partyName                    当事人名称
     * @author xiangyuyu
     * @date 2022-04-25 15:11
     */
    private void generateExecuteConditionRecord(String executeId, List<CaseAttachmentInfoSaveDto> realPlaceCheckRecordFileList, List<CaseAttachmentInfoSaveDto> paymentProofFileList,String partyId,String partyName) {
        ExecuteDocCommonOperateSaveDto saveDto = new ExecuteDocCommonOperateSaveDto();
        HashMap<String, Object> dataMap = new HashMap<>();
        //获取案件信息
        ExecuteMainInfo executeMainInfo = getByExecuteId(executeId);
        //String handleType = caseMainInfo.getHandleType();
        //String partiesReasonType = caseMainInfo.getCasePartiesReasonType();
        /*
        不同处置类型和案件案由类型，取数分析：
        1.单当事人单案由 宽表
        2.单当事人多案由 宽表
        3.多当事人单案由
            -合并处罚 宽表
            -分别处罚 补充表
         */
        dataMap.put("ZXQKJL_DSR", partyName);


        //获取执行完成情况信息
        ExecuteCompleteRecord caseMainDetailInfo = executeCompleteRecordService.getExecuteCompleteRecordByExecuteId(executeId);
        if (ObjectUtils.isEmpty(caseMainDetailInfo)) {
            throw new BusinessException("未匹配到裁执分离详情-caseId：" + executeId);
        }
        String tmp = DateFormatUtils.format(caseMainDetailInfo.getExecuteFinishDate(),"yyyy年MM月dd日");
        //执行完成日期
        dataMap.put("ZXQKJL_ZXWCRQ", tmp);

        //执行情况描述
        String executeConditionDesc = caseMainDetailInfo.getExecuteConditionDesc();
        dataMap.put("ZXQKJL_ZXJCQK", executeConditionDesc);
        //执行方式
        String executeWay = caseMainDetailInfo.getExecuteWay();
        dataMap.put("ZXQKJL_ZXFS", executeWay);

        String documentNumber = executeMainInfo.getRuleNumber();
        dataMap.put("ZXQKJL_BZ",documentNumber);


        //缴款凭证	ZXQKJL_JKPZ
        List<String> urlList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(paymentProofFileList) && paymentProofFileList.size() > 0) {
            for (CaseAttachmentInfoSaveDto e : paymentProofFileList) {
                urlList.add(e.getAppendixUrl());
            }
        }
        /*dataMap.put("ZXQKJL_JKPZ", urlList);*/

        List<Object> jkpzList = new ArrayList<>();
        Map<String,String> jkpzMap = new HashMap<>(20);
        urlList.forEach(e->{
            jkpzMap.put("ZXQKJL_JKPZ",e);
            jkpzList.add(jkpzMap);
        });
        dataMap.put("ZXQKJL_JKPZ_LIST",jkpzList);

        //现场核查记录	ZXQKJL_XCHCJL
        urlList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(realPlaceCheckRecordFileList) && realPlaceCheckRecordFileList.size() > 0) {
            for (CaseAttachmentInfoSaveDto e : realPlaceCheckRecordFileList) {
                urlList.add(e.getAppendixUrl());
            }
        }
        List<Object> xchcjlList = new ArrayList<>();
        Map<String,String> xchcjlMap = new HashMap<>(20);
        urlList.forEach(e->{
            xchcjlMap.put("ZXQKJL_XCHCJL",e);
            xchcjlList.add(xchcjlMap);
        });
        dataMap.put("ZXQKJL_XCHCJL_LIST",xchcjlList);
        /*dataMap.put("ZXQKJL_XCHCJL", urlList);*/
        //获取办案人员
        List<ExecuteHandlePersonRecordVo> caseHandlePersonRecordList = executeHandlePersonRecordService.getCaseHandlePersonRecordListByExecuteId(executeId);
       // List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        String mainHandlerName = "";
        String assistHandlerName = "";

        String mainHandlerCert = "";
        String assistHandlerCert = "";
        for (ExecuteHandlePersonRecordVo handler : caseHandlePersonRecordList) {
            String handlePersonType = handler.getHandlePersonType();
            if (Constant.STRING_1.equals(handlePersonType)) {
                //主办
                mainHandlerName = handler.getHandlePersonName();
                mainHandlerCert = handler.getLawEnforcementCert();
            } else {
                //协办
                assistHandlerName = handler.getHandlePersonName();
                assistHandlerCert = handler.getLawEnforcementCert();
            }
            if (!ObjectUtils.isEmpty(mainHandlerName) && !ObjectUtils.isEmpty(assistHandlerName)) {
                break;
            }
        }
        dataMap.put("ZXQKJL_ZBRYXM", mainHandlerName);
        dataMap.put("ZXQKJL_ZBRYZFZH", mainHandlerCert);
        dataMap.put("ZXQKJL_XBRYXM", assistHandlerName);
        dataMap.put("ZXQKJL_XBRYZFZH", assistHandlerCert);
        //处罚决定书文号 CFJDSWH
        //String kindCode = Constant.STRING_KIND_CODE_CFJDS;
        /*ExecuteDocumentRecordDto documentRecord = executeDocumentRecordService.getExecuteDocumentRecordByKindCode(executeId, kindCode);
        if (ObjectUtils.isEmpty(documentRecord)) {
            throw new BusinessException("未匹配到处罚决定书信息-caseId:" + executeId + ",kindCode:" + kindCode);
        }*/
        String documentCatalogCode = "ZXQKHCJL90AC9";
        saveDto.setExecuteId(executeId);
        saveDto.setDocumentCatalogCode(documentCatalogCode);
        saveDto.setDataMap(dataMap);
        saveDto.setIsUpdateRelationTable(YesOrNoEnum.NO.getCode());
        saveDto.setPartyId(partyId);
        executeDocCommonOperateService.saveDocInfo(saveDto);
    }
}